//
//  ConfigurationManager.m
//  Science
//
//  Created by Draven on 2018/1/15.
//  Copyright © 2018年 Draven. All rights reserved.
//

#import "ConfigurationManager.h"
#import "EnvironmentManager.h"

@interface ConfigurationManager()
@property (copy, nonatomic) NSString *devServer;
@property (copy, nonatomic) NSString *relServer;
@end

@implementation ConfigurationManager
+ (ConfigurationManager *)sharedInstance {
    static dispatch_once_t once;
    static ConfigurationManager *sharedInstance;
    dispatch_once(&once, ^{
        sharedInstance = [[self alloc] initWithConfigFile:@"Configuration"];
    });
    return sharedInstance;
}
- (id)initWithConfigFile:(NSString *)filename {
    NSString *filepath = [[NSBundle mainBundle] pathForResource:filename ofType:@"plist"];
    NSDictionary *dict = [NSDictionary dictionaryWithContentsOfFile:filepath];
    NSError *error = nil;
    self = [super initWithDictionary:dict error:&error];
    if (error) {
        self = [super init];
    }
    return self;
}
- (NSString<Optional> *)url {
#if RELEASE
    return self.relServer;
#else
    switch ([EnvironmentManager sharedInstance].envType) {
            case EnvironmentTypeDev:
            return self.devServer;
            break;
            case EnvironmentTypeRel:
            return self.relServer;
            break;
        default:
            return self.devServer;
            break;
    }
#endif
}
@end
